package com.Ajava1704.多线程使用案例;

import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/2/25  15:51
 * 描述:
 */
public class TestHandler2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        Long start=System.currentTimeMillis();

        List<Map<String,Object>> list=new ArrayList<>();

        for(int i=0;i<40000;i++){

            Map<String,Object> map=new HashMap<>();
            map.put("id",i);
            list.add(map);
        }

        TestHandler testHandler1 = new TestHandler(list.subList(0, 9999));
        TestHandler testHandler2 = new TestHandler(list.subList(10000, 19999));
        TestHandler testHandler3 = new TestHandler(list.subList(20000, 29999));
        TestHandler testHandler4 = new TestHandler(list.subList(30000, 39999));

        CompletableFuture.supplyAsync(()->{
            TestHandler testHandler = new TestHandler(list.subList(0, 9999));
            List<Map<String, Object>> call = null;
            try {
                call = testHandler.call();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return call;
        }).thenAccept(x->{
            System.out.println("----------->"+x.size());
        });


        Long end=System.currentTimeMillis();
        System.out.println(end-start);


    }
}
